package com.example.tourapp.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.tourapp.Adapter.Grid_Adapter;
import com.example.tourapp.Pojo.Mode_index;
import com.example.tourapp.R;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    //组件
    private GridView index_gridview;
    //全局
    private List<Mode_index> list;
    private int[] imge=new int[]{R.mipmap.meishi,R.mipmap.jingdian,R.mipmap.tianqi,R.mipmap.ditu,R.mipmap.biji,R.mipmap.dianhua};
    private int[] imgee=new int[]{R.mipmap.meishi_on,R.mipmap.jingdian_on,R.mipmap.tianqi_on,R.mipmap.ditu_on,R.mipmap.biji_on,R.mipmap.dianhua_on};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        index_gridview = (GridView) findViewById(R.id.index_gridview);
    }

    private void inifunction() {
        list=new ArrayList<>();
        for (int i = 0; i < imge.length; i++) {
            Mode_index index=new Mode_index();
            index.setImg(imge[i]);
            list.add(index);
        }
        Grid_Adapter adapter=new Grid_Adapter(list,this,R.id.index_img,R.layout.mode_index,null);
        index_gridview.setAdapter(adapter);
        //item点击
        index_gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
               ImageView img= view.findViewById(R.id.index_img);
               img.setImageResource(imgee[i]);
                switch (i)
                {
                    case 0:
                      jump(Fine_food.class);
                        break;
                    case 1:
                    jump(Tour.class);
                        break;
                    case 2:
                        jump(City.class);
                        break;
                    case 3:
                        jump(Line_chart.class);
                        break;
                    case 4:
                        jump(Note.class);
                        break;
                    case 5:
                        jump(Telephone.class);
                        break;
                }
            }
        });

    }
    public void jump(Class pager)
    {
        Intent intent=new Intent(MainActivity.this,pager);
        startActivity(intent);
    }

    //调用继续方法，恢复itme图片
    @Override
    protected void onResume() {
        super.onResume();

        inifunction();
    }
}